// import { themes } from './themes';
import { ref } from 'vue'
import { themes } from "./themes"
// 修改样式变量值
const changeStyle = (obj:any)=>{
  for(let key in obj){
    document.getElementsByTagName("body")[0].style.setProperty(`--${key}`, obj[key])
  }
}
// 用ref将引入的themes处理一下，将其类型设为any，避免下面直接const themeConfig = themes[themeName]，打包时报错
const configObj:any = ref(themes)
export const setTheme = (themeName:string) => {
  localStorage.setItem("theme", themeName);//保存主题到本地，下次进入使用该主题
  const themeConfig = configObj.value[themeName];
  localStorage.setItem("colors", JSON.stringify(themeConfig));//保存色彩到本地，下次进入使用该主题
  changeStyle(themeConfig);
}